﻿using Prism.Regions;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace PrismRegion.Base.Views
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        IRegionManager _regionManager;
        public MainWindow(IRegionManager regionManager)
        {
            InitializeComponent();
            _regionManager = regionManager;

            //向ViewRegion区域添加一个ViewA
            //regionManager.RegisterViewWithRegion("ContentRegion", "ViewA");//注册导航页面
            //regionManager.RegisterViewWithRegion("ContentRegion", "ViewB");


            this.Loaded += (se,ev)=>
            {
                //var region = regionManager.Regions["ContentRegion"];
                //var view = region.Views.FirstOrDefault(v => v.GetType().Name == "ViewB");
                //region.Activate(view);



                var region = _regionManager.Regions["ContentRegion"];
                region.Add(new ViewA(), "ViewA");
            };

        }

        private void Button1_Click(object sender, RoutedEventArgs e)
        {
            var region = _regionManager.Regions["ContentRegion"];
            var view = region.Views.FirstOrDefault(v => v.GetType().Name == "ViewA");
            region.Activate(view);
        }

        private void Button2_Click(object sender, RoutedEventArgs e)
        {
            var region = _regionManager.Regions["ContentRegion"];
            var view = region.Views.FirstOrDefault(v => v.GetType().Name == "ViewB");
            region.Activate(view);
        }

        private void Button3_Click(object sender, RoutedEventArgs e)
        {

        }
    }
}